#include "gtkviewport.h"
#include "gtkadjustment.h"
-#include "gtkcsscustomgadgetprivate.h"
#include "gtkintl.h"
#include "gtkmarshalers.h"
#include "gtkprivate.h"
GdkWindow *bin_window;
- GtkCssGadget *gadget;
-
/* GtkScrollablePolicy needs to be checked when
* driving the scrollable adjustment values */
guint hscroll_policy : 1;
guint prop_id,
GValue *value,
GParamSpec *pspec);
-static void gtk_viewport_finalize (GObject *object);
static void gtk_viewport_destroy (GtkWidget *widget);
static void gtk_viewport_realize (GtkWidget *widget);
static void gtk_viewport_unrealize (GtkWidget *widget);
G_ADD_PRIVATE (GtkViewport)
G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL))
-static void
-gtk_viewport_measure (GtkCssGadget *gadget,
- GtkOrientation orientation,
- int for_size,
- int *minimum,
- int *natural,
- int *minimum_baseline,
- int *natural_baseline,
- gpointer data)
-{
- GtkWidget *widget = gtk_css_gadget_get_owner (gadget);
- GtkWidget *child;
-
- *minimum = *natural = 0;
-
- child = gtk_bin_get_child (GTK_BIN (widget));
- if (child && gtk_widget_get_visible (child))
- gtk_widget_measure (child,
- orientation,
- for_size,
- minimum, natural,
- NULL, NULL);
-}
-
static void
viewport_set_adjustment_values (GtkViewport *viewport,
GtkOrientation orientation)
gdouble upper, value;
int viewport_size, other_viewport_size;
- gtk_css_gadget_get_content_allocation (viewport->priv->gadget,
- &view_allocation, NULL);
+ gtk_widget_get_content_allocation (GTK_WIDGET (viewport), &view_allocation);
if (orientation == GTK_ORIENTATION_HORIZONTAL)
{
}
static void
-gtk_viewport_allocate (GtkCssGadget *gadget,
- const GtkAllocation *allocation,
- int baseline,
- GtkAllocation *out_clip,
- gpointer data)
-{
- GtkWidget *widget = gtk_css_gadget_get_owner (gadget);
- GtkViewport *viewport = GTK_VIEWPORT (widget);
- GtkViewportPrivate *priv = viewport->priv;
- GtkAdjustment *hadjustment = priv->hadjustment;
- GtkAdjustment *vadjustment = priv->vadjustment;
- GtkWidget *child;
-
- g_object_freeze_notify (G_OBJECT (hadjustment));
- g_object_freeze_notify (G_OBJECT (vadjustment));
-
- viewport_set_adjustment_values (viewport, GTK_ORIENTATION_HORIZONTAL);
- viewport_set_adjustment_values (viewport, GTK_ORIENTATION_VERTICAL);
-
- if (gtk_widget_get_realized (widget))
- {
- gdk_window_move_resize (priv->bin_window,
- allocation->x - gtk_adjustment_get_value (hadjustment),
- allocation->y - gtk_adjustment_get_value (vadjustment),
- gtk_adjustment_get_upper (hadjustment),
- gtk_adjustment_get_upper (vadjustment));
- }
-
- child = gtk_bin_get_child (GTK_BIN (widget));
- if (child && gtk_widget_get_visible (child))
- {
- GtkAllocation child_allocation;
-
- child_allocation.x = 0;
- child_allocation.y = 0;
- child_allocation.width = gtk_adjustment_get_upper (hadjustment);
- child_allocation.height = gtk_adjustment_get_upper (vadjustment);
-
- gtk_widget_size_allocate (child, &child_allocation);
- }
-
- g_object_thaw_notify (G_OBJECT (hadjustment));
- g_object_thaw_notify (G_OBJECT (vadjustment));
-}
-
-static gboolean
-gtk_viewport_render (GtkCssGadget *gadget,
- GtkSnapshot *snapshot,
- int x,
- int y,
- int width,
- int height,
- gpointer data)
-{
- GtkWidget *widget = gtk_css_gadget_get_owner (gadget);
-
- gtk_snapshot_push_clip (snapshot, &GRAPHENE_RECT_INIT(x, y, width, height), "Viewport");
-
- GTK_WIDGET_CLASS (gtk_viewport_parent_class)->snapshot (widget, snapshot);
-
- gtk_snapshot_pop (snapshot);
-
- return FALSE;
-}
-
-static void
-gtk_viewport_measure_ (GtkWidget *widget,
+gtk_viewport_measure (GtkWidget *widget,
GtkOrientation orientation,
int for_size,
int *minimum,
int *minimum_baseline,
int *natural_baseline)
{
- gtk_css_gadget_get_preferred_size (GTK_VIEWPORT (widget)->priv->gadget,
- orientation,
- for_size,
- minimum, natural,
- minimum_baseline, natural_baseline);
+ GtkWidget *child;
+
+ *minimum = *natural = 0;
+
+ child = gtk_bin_get_child (GTK_BIN (widget));
+ if (child && gtk_widget_get_visible (child))
+ gtk_widget_measure (child,
+ orientation,
+ for_size,
+ minimum, natural,
+ NULL, NULL);
}
static void
gobject_class->set_property = gtk_viewport_set_property;
gobject_class->get_property = gtk_viewport_get_property;
- gobject_class->finalize = gtk_viewport_finalize;
widget_class->destroy = gtk_viewport_destroy;
widget_class->realize = gtk_viewport_realize;
widget_class->unrealize = gtk_viewport_unrealize;
widget_class->snapshot = gtk_viewport_snapshot;
widget_class->size_allocate = gtk_viewport_size_allocate;
- widget_class->measure = gtk_viewport_measure_;
+ widget_class->measure = gtk_viewport_measure;
gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_VIEWPORT);
{
GtkWidget *widget;
GtkViewportPrivate *priv;
- GtkCssNode *widget_node;
viewport->priv = gtk_viewport_get_instance_private (viewport);
priv = viewport->priv;
priv->hadjustment = NULL;
priv->vadjustment = NULL;
- widget_node = gtk_widget_get_css_node (widget);
- priv->gadget = gtk_css_custom_gadget_new_for_node (widget_node,
- widget,
- gtk_viewport_measure,
- gtk_viewport_allocate,
- gtk_viewport_render,
- NULL, NULL);
-
- gtk_css_gadget_add_class (priv->gadget, GTK_STYLE_CLASS_FRAME);
+ gtk_style_context_add_class (gtk_widget_get_style_context (widget),
+ GTK_STYLE_CLASS_FRAME);
viewport_set_adjustment (viewport, GTK_ORIENTATION_HORIZONTAL, NULL);
viewport_set_adjustment (viewport, GTK_ORIENTATION_VERTICAL, NULL);
}
GTK_WIDGET_CLASS (gtk_viewport_parent_class)->destroy (widget);
}
-static void
-gtk_viewport_finalize (GObject *object)
-{
- GtkViewport *viewport = GTK_VIEWPORT (object);
- GtkViewportPrivate *priv = viewport->priv;
-
- g_clear_object (&priv->gadget);
-
- G_OBJECT_CLASS (gtk_viewport_parent_class)->finalize (object);
-}
-
static void
viewport_set_adjustment (GtkViewport *viewport,
GtkOrientation orientation,
GTK_WIDGET_CLASS (gtk_viewport_parent_class)->realize (widget);
- gtk_css_gadget_get_content_allocation (priv->gadget,
- &view_allocation, NULL);
+ gtk_widget_get_content_allocation (widget, &view_allocation);
priv->bin_window = gdk_window_new_child (gtk_widget_get_window (widget),
GDK_ALL_EVENTS_MASK,
&(GdkRectangle) {
- - gtk_adjustment_get_value (hadjustment),
- - gtk_adjustment_get_value (vadjustment),
+ view_allocation.x - gtk_adjustment_get_value (hadjustment),
+ view_allocation.y - gtk_adjustment_get_value (vadjustment),
gtk_adjustment_get_upper (hadjustment),
gtk_adjustment_get_upper (vadjustment)});
gtk_widget_register_window (widget, priv->bin_window);
gtk_viewport_snapshot (GtkWidget *widget,
GtkSnapshot *snapshot)
{
- GtkViewport *viewport = GTK_VIEWPORT (widget);
- GtkViewportPrivate *priv = viewport->priv;
+ GtkAllocation content_allocation;
+ GtkAllocation widget_allocation;
+
+ gtk_widget_get_content_allocation (widget, &content_allocation);
+ gtk_widget_get_allocation (widget, &widget_allocation);
- gtk_css_gadget_snapshot (priv->gadget, snapshot);
+ gtk_snapshot_push_clip (snapshot,
+ &GRAPHENE_RECT_INIT(
+ content_allocation.x - widget_allocation.x,
+ content_allocation.y - widget_allocation.y,
+ content_allocation.width,
+ content_allocation.height),
+ "Viewport");
+
+ GTK_WIDGET_CLASS (gtk_viewport_parent_class)->snapshot (widget, snapshot);
+
+ gtk_snapshot_pop (snapshot);
}
static void
static void
gtk_viewport_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation)
+ GtkAllocation *allocation)
{
GtkViewport *viewport = GTK_VIEWPORT (widget);
GtkViewportPrivate *priv = viewport->priv;
- GtkAllocation clip, content_allocation, widget_allocation;
+ GtkAllocation clip = *allocation, widget_allocation;
+ GtkAdjustment *hadjustment = priv->hadjustment;
+ GtkAdjustment *vadjustment = priv->vadjustment;
+ GtkWidget *child;
/* If our size changed, and we have a shadow, queue a redraw on widget->window to
* redraw the shadow correctly.
widget_allocation.height != allocation->height))
gdk_window_invalidate_rect (gtk_widget_get_window (widget), NULL, FALSE);
- gtk_widget_set_allocation (widget, allocation);
+ g_object_freeze_notify (G_OBJECT (hadjustment));
+ g_object_freeze_notify (G_OBJECT (vadjustment));
+
+ viewport_set_adjustment_values (viewport, GTK_ORIENTATION_HORIZONTAL);
+ viewport_set_adjustment_values (viewport, GTK_ORIENTATION_VERTICAL);
+
+ if (gtk_widget_get_realized (widget))
+ {
+ gdk_window_move_resize (priv->bin_window,
+ allocation->x - gtk_adjustment_get_value (hadjustment),
+ allocation->y - gtk_adjustment_get_value (vadjustment),
+ gtk_adjustment_get_upper (hadjustment),
+ gtk_adjustment_get_upper (vadjustment));
+ }
+
+ child = gtk_bin_get_child (GTK_BIN (widget));
+ if (child && gtk_widget_get_visible (child))
+ {
+ GtkAllocation child_allocation;
+
+ child_allocation.x = 0;
+ child_allocation.y = 0;
+ child_allocation.width = gtk_adjustment_get_upper (hadjustment);
+ child_allocation.height = gtk_adjustment_get_upper (vadjustment);
+
+ gtk_widget_size_allocate (child, &child_allocation);
+ gtk_widget_get_clip (child, &clip);
+ }
- content_allocation = *allocation;
- gtk_css_gadget_allocate (priv->gadget,
- &content_allocation,
- gtk_widget_get_allocated_baseline (widget),
- &clip);
+ g_object_thaw_notify (G_OBJECT (hadjustment));
+ g_object_thaw_notify (G_OBJECT (vadjustment));
gtk_widget_set_clip (widget, &clip);
}
gint old_x, old_y;
gint new_x, new_y;
- gtk_widget_get_allocation (GTK_WIDGET (viewport), &allocation);
+ gtk_widget_get_content_allocation (GTK_WIDGET (viewport), &allocation);
gdk_window_get_position (priv->bin_window, &old_x, &old_y);
new_x = - gtk_adjustment_get_value (hadjustment);
new_y = - gtk_adjustment_get_value (vadjustment);